import { defineEventHandler, getRouterParam, readBody } from 'h3';

// 资源可用性状态枚举
enum ResourceAvailabilityStatus {
  AVAILABLE = 'AVAILABLE',
  RESERVED = 'RESERVED',
  IN_USE = 'IN_USE',
  UNAVAILABLE = 'UNAVAILABLE',
  FAILED = 'FAILED',
}

export default defineEventHandler(async (event) => {
  const resourceId = getRouterParam(event, 'resourceId');
  const body = await readBody(event);
  const { status, reason } = body;

  // 验证状态值
  if (!Object.values(ResourceAvailabilityStatus).includes(status)) {
    return {
      code: 400,
      msg: '无效的可用性状态',
    };
  }

  // 模拟状态更新
  const result = {
    resourceId,
    status,
    reason,
    updatedAt: new Date().toISOString(),
    operator: 'admin',
  };

  return {
    code: 0,
    data: result,
    msg: '资源可用性状态更新成功',
  };
});
